﻿using System;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using ZX.SYS.Library;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;
//using ZX.Mapping;

namespace ZX.WebApp.Crm.Customer
{
    public partial class EditCrmManager : EditUIPage
    {
        BTCrmCustomer bll = new BTCrmCustomer();
        BDatPhraseDetail bllDetail = new BDatPhraseDetail();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    ID.Value = Guid.NewGuid().ToString();
                    InitData();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {   
            //自动生成联系人编码
            Code.Text = ZX.BLL.IDMaker.GetSequenceStr("CUS002");
            IList<DatPhraseDetail> listLinkType = bllDetail.GetDatPhraseDetailByClassValue("LinkmanType");
            DropDownListControl.DropDataSourceBind(this.TypeID, listLinkType, "PhraseText", "PhraseID");
            IList<DatPhraseDetail> listRelation = bllDetail.GetDatPhraseDetailByClassValue("Relation");
            DropDownListControl.DropDataSourceBind(this.Relation, listRelation, "PhraseText", "PhraseID"); 
            string strId = this.GetStringFromQueryString("id", "");//联系人记录ID
            string cid = this.GetStringFromQueryString("cid", "");  //客户ID
            if (cid != "")
            {
                CustomId.Value = cid;
                IList<V_CrmCustomerInfo> vis = bll.GetAllV_CrmCustomerInfos(new Guid(cid));
                if (vis != null && vis.Count > 0)
                {
                    txtCustomId.Value = bll.GetAllV_CrmCustomerInfos(new Guid(cid))[0].CustomerName;
                }
            }
            //修改给各元素赋值
            if (strId != "" && DataAction != "insert")
            {

                CrmLinkMan clm = bll.GetCrmLinkManInfo(new Guid(strId));
                if (clm != null)
                {
                    //Using UIMapping replace here!
                    //ZX.Mapping.IMapping mapper = new ZX.Mapping.WebUiEnMapper(Orders, this);
                    //mapper.EN2UI();

                    ID.Value = clm.ID.ToString();
                    Code.Text = clm.Code;
                    Caption.Text = clm.Caption;
                    TypeID.SelectedValue = clm.TypeID.ToString();
                    Sex.SelectedValue = clm.Sex;
                    Nation.Text = clm.Nation;
                    Position.Text = clm.Position;
                    Birthday.Value = clm.Birthday.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : clm.Birthday.ToString("yyyy-MM-dd");
                    DeptName.Text = clm.DeptName;
                    Homeplace.Text = clm.Homeplace;
                    BirthdayType.SelectedValue = clm.BirthdayType;
                    CustomId.Value = clm.CustomId.ToString();
                    //txtCustomId.Value = txtCustomId.Value == "" ? bll.GetAllCustomerInfo(clm.CustomId)[0].CustomerName : txtCustomId.Value;
                    SchoolUntity.Text = clm.SchoolUntity;
                    Schoolspeciality.Text = clm.Schoolspeciality;
                    LinkManFancy.Text = clm.LinkManFancy;
                    MobileTel.Text = clm.MobileTel;
                    Email.Text = clm.Email;
                    Fax.Text = clm.Fax;
                    Medical.Text = clm.Medical;
                    Religion.Text = clm.Religion;
                    HomeTel.Text = clm.HomeTel;
                    OfficeTel.Text = clm.OfficeTel;
                    Netting.Text = clm.Netting;
                    HoliType.Text = clm.HoliType;
                    Address.Text = clm.Address;
                    Explain.Text = clm.Explain;
                    FereName.Text = clm.FereName;
                    FereNation.Text = clm.FereNation;
                    FereHomeplace.Text = clm.FereHomeplace;
                    FereFancy.Text = clm.FereFancy;
                    FereBirthday.Text = clm.FereBirthday;
                    FereCompany.Text = clm.FereCompany;
                    ChildName.Text = clm.ChildName;
                    ChildBirthday.Text = clm.ChildBirthday;
                    ChildFancy.Text = clm.ChildFancy;
                    ChildCompany.Text = clm.ChildCompany;
                    EXP1.Text = clm.EXP1;  //子女民族
                    EXP2.Text = clm.EXP2;  //子女籍贯
                    EXP3.Value = clm.EXP3; //年
                    EXP4.Value = clm.EXP4; //月
                    Drink.Value = clm.Drink;//日
                    Dish.Text = clm.Dish;
                    AddUser.Value = clm.AddUser.ToString();
                    AddTime.Value = clm.AddTime.ToString();
                    txtWeibo.Text = clm.Weibo;
                    Relation.SelectedValue = clm.Relation.ToString();
                }
            }
        }
      
        public string getId { get{return this.GetStringFromQueryString("id","");}}
    }
}